<?php
namespace Home\Controller;
use Think\Controller;

class UserController extends Controller{
    public function done(){
        // $a = D('Xxx','Tool');
        new \Home\Tool\XxxTool();
        $a->xx();
        $this->display();
    }
    public function login(){

        // var_dump($_POST);
        if(IS_POST){
            $verify = new \Think\Verify();
            if(!$verify->check($_POST['yzm'])){
                echo '验证码不对啊^';
            }
            $uModel = D('User');
            $username = $_POST['username'];
            $userinfo = $uModel->where('username='.$username)->find();
            if($userinfo['password'] == md5($_POST['password'].$userinfo['salt'])){
                cookie('username',$userinfo['username']);
                cookie('email',$userinfo['email']);
                cookie('aabb',md5($userinfo['username'].C('JIA')));
                $this->redirect('/');
            }else{
                echo 'cuola';
            }

        }

        $this->display();
    }
    public function msg(){
        $this->display();
    }
    public function reg(){
        if(IS_POST){

            // $_POST['password']=md5($_POST['password']);
            // $_POST['confirm_password']=md5($_POST['confirm_password']);
            $userModel = D('User');
            if(!$userModel->create()){
                echo $userModel->getError();
            }
            $salt = mt_rand(1000,9999);
            $userModel->password = md5($userModel->password.$salt);
            $userModel->salt = $salt;
            $userModel->add();
        }
        $this->display();
    }
    public function yzm(){
        // $c = array(
        //     'useZh'     =>  true,
        //     'fontttf'   =>  '5.ttf',
        // );
        $Verify = new \Think\Verify();
        // $Verify->useZh = true;
        // $Verify->fontttf = '5.ttf';
        // $Verify->fontSize = 30;
        // $Verify->zhSet = '们以我到他会作时要动国产的一是工就年阶义发成部民可出能方进在了不和有大这';
        $Verify->length   = 3;
        $Verify->entry();
    }
}
